package com.it.gw.modules.water.adapter

import ADNMVo
import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.it.gw.R
import com.it.gw.databinding.ItemSelectAddvcdBinding


class ADDVCDAdapter(
    var context: Context,
    var listener: ((ADNMVo) -> Unit)? = null,
    var datas: List<ADNMVo>
) : RecyclerView.Adapter<ADDVCDAdapter.ViewHolder>() {
    companion object {
        const val TAG = "ADDVCDAdapter"
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): ViewHolder {
        //横向没有铺满
        val binding = ItemSelectAddvcdBinding.inflate(LayoutInflater.from(parent.context),parent,false)
        return ViewHolder(binding)
    }


    override fun onBindViewHolder(holder: ViewHolder, @SuppressLint("RecyclerView") position: Int) {
        val data = datas[position]
        Log.d(TAG, "onBindViewHolder: $data")
        holder.binding.name.text = data.ADNM
        if(data.selected==true){
            holder.binding.name.setTextColor(ContextCompat.getColor(context, R.color.color_0F6AF8))
        }
        else{
            holder.binding.name.setTextColor(ContextCompat.getColor(context, R.color.color_1C1F2E))
        }
        holder.binding.root.setOnClickListener {
            listener?.invoke(data)
        }


    }

    override fun getItemCount() = datas.size

    class ViewHolder(val binding: ItemSelectAddvcdBinding) :
        RecyclerView.ViewHolder(binding.root)
}